<? include_once("../../../common/common_setting_unit.php"); //引入通用的设置文件?>

<?
//引入所有子系统信息
include_once("../../../common/script/extender_import.php");


//**获取当前板块资料，必然载入，后续很多读取板块数据库的表格，都写成动态的了。
include_once("script/this_plate.php");



$_data=select($table_prefix.$this_plate['table']['data'],$_REQUEST['nid'])[0];



    $table= $table_prefix.$this_plate['table']['data'];
    $nid  =$_REQUEST['nid'];

    $_data['ai_delete_status']="已删除";
    $_delete_sql=update_date($table,$_data,"nid",$nid);
    $query=execute_query($_delete_sql);



//删除分类信息
if($query)
{
    $relation_delete_sql=update_date($table_prefix.$this_plate['table']['relation'],$_data,"data_nid",$nid);
    $relation_delete_query=execute_query($relation_delete_sql);
}






if($query)
{
    $_image_upload_list_to_check =
        ['icon',
            'image1','image2','image3','image4','image5',
            'image6','image7','image8','image9','image10',
            'video', 'banner', 'attachment', 'extend_img'];

//循环判断检查所有要上传的图片，去做移动
    foreach ($_image_upload_list_to_check as $value)
    {
        if(isset($_REQUEST['ai_'.$value]))
        {

            $source      = ROOT_PATH_ . "/uploadfiles".$_data['ai_'.$value];
            $destination = ROOT_PATH_ . "/uploadfiles/".$_REQUEST['ai_'.$value];

            if (file_exists($source))
            {
                if (copy($source, $destination))
                {
                    unlink($source); // 删除源文件
                }
                else
                {
                    error_log("Failed to copy file from $source to $destination");
                }
            }


            //******************************************
            //获取新数据的图片，，用于对比删除
            //******************************************

            if($old_detail[$value] != $_REQUEST['ai_'.$value])
            {

                $source      = ROOT_PATH_ . "/uploadfiles/".$old_detail[$value];
                $destination = ROOT_PATH_ . "/uploadfiles/delete/".$old_detail[$value];

                if (copy($source, $destination))
                {
                    unlink($source); // 删除源文件
                }

            }


        }
    }
}

//******************************************
//判断是否更新成功，然后把图片从temp目录移动出来
//******************************************





    if($query){
        $arr['status'] = 200;
        $arr['info'] = '删除成功';
        die(json_encode($arr)) ;
    }
    else
    {
        $arr['status'] = 201;
        $arr['info'] = '删除失败';
        die(json_encode($arr)) ;
    }

?>



